package com.lanhao.aot.redis;

import java.util.Map;

import com.google.common.collect.Maps;

public class RedisShardingTool {
	public static Map<String, String> redisShardingMap = Maps.newConcurrentMap();
	// Redis分片实例的部署个数，此值需要根据实际现网数量变化
	public static final int RedisShardingNum = 12;
	static {
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "1","10.251.160.20:16379,10.251.160.21:16379,10.251.160.22:16379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "2","10.251.160.22:26379,10.251.160.23:26379,10.251.160.24:26379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "3","10.251.160.24:16379,10.251.160.25:16379,10.251.160.26:16379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "4","10.251.160.26:26379,10.251.160.27:26379,10.251.160.28:26379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "5","10.251.160.28:16379,10.251.160.29:16379,10.251.160.30:16379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "6","10.251.160.30:26379,10.251.160.31:26379,10.251.160.32:26379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "7","10.251.160.32:16379,10.251.160.33:16379,10.251.160.34:16379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "8","10.251.160.34:26379,10.251.160.35:26379,10.251.160.36:26379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "9","10.251.160.36:16379,10.251.160.37:16379,10.251.160.38:16379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "10","10.251.160.38:26379,10.251.160.39:26379,10.251.160.40:26379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "11","10.251.160.40:16379,10.251.160.41:16379,10.251.160.42:16379");
		redisShardingMap.put(Const.PREFIX_SLOT_NAME + "12","10.251.160.42:26379,10.251.160.43:26379,10.251.160.20:26379");
		RedisShardingUtil.initRedisGroup(RedisShardingNum);
	}
	
	public static void main(String[] args) {
		String redisKey = "-03e95r08435690iklxcjvnksedrhjg9iuerj";
		String slotName = RedisShardingUtil.findSlot(redisKey);
		String redisHost = redisShardingMap.get(slotName);
		System.out.println("本次通过key=" + redisKey + "找到的Redis分片实例名称为：" + slotName + "\r 对应Redis哨兵连接信息为：" + redisHost);
	}
}
